﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using DepartmentWork.Model
@model DepartmentWork.Model.TeamSpaceRoleViewModel

<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-Control" content="no-cache,must-revalidate"/>
<meta http-equiv="expires" content="0"/>

<link href="~/Assets/plugins/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" />
<script src="~/Assets/plugins/bootstrap-select/bootstrap-select.min.js"></script>
<link href="~/Assets/plugins/bootstrap-datepicker/css/datepicker3.css" rel="stylesheet" />
<link href="~/Assets/plugins/bootstrap-datepicker/css/datepicker-theme.css" rel="stylesheet" />
<script src="~/Assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script src="~/Assets/plugins/chosen/chosen.jquery.min.js"></script>
<script src="~/Assets/js/pages/form-elements.js"></script>
<style>
    .btn-default {
        color: #333;
        background-color: #FFF;
        border-color: #CCC;
        height: 34px;
    }
</style>
<script>
    $(document).ready(function() {
        //$("#RoleEditModal #select_EditRoleMenu").selectpicker('refesh');
        //$("#RoleEditModal #select_EditRoleMenu").trigger('liszt:updated');
    });
    
    function DelRole(roleId)
    {
        if (!confirm("请确认是否删除该权限？"))
        {
            return false;
        }
        window.location.href = '@Url.Action("DelRole", "Role", new { area = "SystemSettingArea" })' + '?roleId=' + roleId;
    }

</script>


<div class="page-header">
    <div class="pull-left">
        <ol class="breadcrumb visible-sm visible-md visible-lg">
            <li><a href="index.html"><i class="icon fa fa-home"></i>主页</a></li>
            <li><a href="#"><i class="fa fa-envelope"></i>系统设置</a></li>
            <li class="active"><a href="#"><i class="fa fa-envelope"></i>权限管理</a></li>
        </ol>
    </div>
</div>

@{
    if (ViewBag.Flag == "CreateTrue")
    {
    <div class="alert alert-success">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <strong>&emsp;权限添加成功！</strong>
    </div>
    }
    if (ViewBag.Flag == "CreateFalse")
    {
      <div class="alert alert-danger">
	    <button type="button" class="close" data-dismiss="alert">×</button>
	    <strong>&emsp;权限添加失败！</strong> @ViewBag.Info
    </div>
    }
    
    if (ViewBag.Flag == "EditTrue")
    {
    <div class="alert alert-success">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <strong>&emsp;权限编辑成功！</strong>
    </div>
    }
    if (ViewBag.Flag == "EditFalse")
    {
      <div class="alert alert-danger">
	    <button type="button" class="close" data-dismiss="alert">×</button>
	    <strong>&emsp;权限辑失败！</strong> @ViewBag.Info
    </div>
    }
    
    if (ViewBag.Flag == "DelTrue")
    {
    <div class="alert alert-success">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <strong>&emsp;权限删除成功！</strong>
    </div>
    }
    if (ViewBag.Flag == "DelFalse")
        {
      <div class="alert alert-danger">
	    <button type="button" class="close" data-dismiss="alert">×</button>
	    <strong>&emsp;权限删除失败！</strong> @ViewBag.Info
    </div>
        }
    
}

<div class="row">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading bk-bg-primary">
                <h6><i class="fa fa-table red"></i><span style="font-size: medium" class="break">权限列表</span></h6>
                @{
                    if (ViewBag.IsAdmin == true)
                    {
                        <div class="panel-actions">
                            <a data-toggle="modal" data-target="#createRoleModal" class="bk-margin-5 btn btn-default  btn-sm" style="background-color: #ECEDF0">&nbsp;&nbsp;新增权限&nbsp;&nbsp;</a>
                        </div>
                    }
                }

            </div>
            <div class="panel-body">
                <div class="tabs">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="#@this.Model.teamSpaceList[0].TEAMSPACE_ID" data-toggle="tab">@this.Model.teamSpaceList[0].TEAMSPACE_NAME</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered bootstrap-datatable datatable">
                                    <thead>
                                        <tr>
                                            <th>角色名称</th>
                                            <th>角色说明</th>
                                            <th>角色状态</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @{
                                            for (int j = 0; j < this.Model.roleList.Count(); j++)
                                            {
                                                if (this.Model.roleList[j].TEAMSPACE_ID == this.Model.teamSpaceList[0].TEAMSPACE_ID)
                                                {
                                                    <tr>
                                                        <td>
                                                              <a  data-target="#RoleInfoModal" onclick="ShowRoleInfoModal('@this.Model.roleList[j].ROLE_ID')" data-toggle="modal" style="color:black">
                                                                @this.Model.roleList[j].ROLE_NAME
                                                            </a>
                                                        </td>
                                                        <td>@this.Model.roleList[j].DESCRIPTION</td>
                                                        <td>
                                                            @{
                                                                if (this.Model.roleList[j].STATUE==0)
                                                                {
                                                                        <span class="label label-success">正常</span>
                                                                }
                                                                else
                                                                {
                                                                        <span class="label label-info">冻结</span>
                                                                }
                                                            }
                                                        </td>
                                                        <td>
                                                            @{
                                                                if (ViewBag.IsAdmin == true)
                                                                {
                                                                    <a data-toggle="modal" data-target="#RoleEditModal" class="btn btn-info" onclick="ShowRoleEditModal('@this.Model.roleList[j].ROLE_ID')">
                                                                        <i class="fa fa-edit "></i>
                                                                    </a>
                                                                    <a class="btn btn-danger" onclick="DelRole('@this.Model.roleList[j].ROLE_ID')">
                                                                        <i class="fa fa-trash-o "></i>
                                                                    </a>
                                                                }
                                                            }
                                                        </td>
                                                    </tr>
                                                }
                                            }
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- 新增模态框（Modal） -->



@{
    List<MenuViewModel> allMenuList = (List<MenuViewModel>)TempData["MenuList"];
}

<div class="modal fade" id="createRoleModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    
    
    <script>
        function SubmitCreate()
        {
            var message = "";
            if ($("#tb_RoleName").val() == "" || $.trim($("#tb_RoleName").val()) == "")
            {
                message += " · 角色名称不能为空" + "<br/>";
            }
            if ($("#tb_CreateRoleContext").val() == "")
            {
                message += " · 角色描述不能为空" + "<br/>";
            }
            if (message != "")
            {
                $("#lb_CheckCreateRoleMessage").html(message);
                $("#div_CheckCreateRoleMessage").css("display", "block");
                return false;
            }
            else
            {
                $("#lb_CheckCreateRoleMessage").html("");
                $("#div_CheckCreateRoleMessage").css("display", "none");
                $("#frm_CreateRole").submit();
            }
        }
</script>
    

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">新增角色权限
                </h4>
            </div>
            <form id="frm_CreateRole" action="@Url.Action("CreateRole", "Role")" method="POST" >
                <div class="modal-body">
                    <div class="alert alert-danger" id="div_CheckCreateRoleMessage" style="display:none">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong><label id="lb_CheckCreateRoleMessage"></label></strong>
                    </div>
                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">角色名称：</label>
                        <div class="col-md-9">
                            <input id="tb_RoleName" name="tb_RoleName" style="border-color: cornflowerblue"  class="form-control" placeholder="Text" type="text">
                        </div>
                    </div>
                    <hr />

                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">角色描述：</label>
                        <div class="col-md-9">
                            <textarea id="tb_CreateRoleContext" name="tb_CreateRoleContext" class="form-control" rows="3"></textarea>
                        </div>
                    </div>
                    <hr />

                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">角色所具有的菜单权限：</label>
                        <div class="col-md-9">
                            @*<select name="select_CreateRoleMenu" id="select_CreateRoleMenu" multiple="multiple" class="form-control selectpicker">
                                @{
                                    if (allMenuList != null)
                                    {
                                        for (int i = 0; i < allMenuList.Count(); i++)
                                        {
                                            <option value="@allMenuList[i].MENU_ID">@allMenuList[i].MENU_NAME</option>
                                        }
                                    }
                                }
                            </select>*@
                            
                            @{
                                if (allMenuList != null)
                                {
                                    for (int i = 0; i < allMenuList.Count(); i++)
                                    {
                                        <input id="ck_@allMenuList[i].MENU_ID" name="ck_CreateRoleMenu" value="@allMenuList[i].MENU_ID"  type="checkbox" />
                                        <label for="lb_EditStatus">@allMenuList[i].MENU_NAME</label>
                                        @:&nbsp;&nbsp;
                                        if (i % 2 != 0)
                                        {
                                            <br/>
                                        }
                                    }
                                }
                            }
                        </div>
                    </div>
                    <hr />
                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">角色是否启用：</label>
                        <div class="col-md-9">
                            <div class="checkbox-custom checkbox-inline" style="width: 50%">
                                <input id="ck_CreateStatus" name="ck_CreateStatus"  type="checkbox">
                                <label for="ck_CreateStatus">启用</label>
                            </div>
                        </div>
                    </div>
                    <hr />

                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                    <input type="button" onclick="SubmitCreate()" class="btn btn-primary" value="新增" />
                </div>
            </form>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>


<!-- 详情模态框（Modal） -->
<script>
    function ShowRoleInfoModal(roleId) {
        $("#RoleInfoModal #div_RoleInfoMenu #lb_RoleMenuInfo").html("");
        $.ajax({
            type: "POST",
            url: "/SystemSettingArea/Role/GetRoleInfo",
            data: "roleId=" + roleId,
            error: function () { alert("服务器出错！"); },
            success: function (data)
            {
                // $("#TaskBookInfoModal").attr("aria-hidden", "true");
                $("#lb_RoleName").text(data["ROLE_NAME"]);
                //$("#lb_RoleDescription").text(data["DESCRIPTION"]);
                
                var content = "";
                for (var i = 0; i < data["DESCRIPTION"].length; i++)
                {
                    if (i % 35 == 0 && i != 0)
                    {
                        content += data["DESCRIPTION"][i] + "<br/>";
                    } else
                    {
                        content += data["DESCRIPTION"][i];
                    }

                }
                $("#lb_RoleDescription").html(content);


                if (data["STATUE"]=="0")
                {
                    $("#lb_RoleStatue").text("启用");
                }
                else
                {
                    $("#lb_RoleStatue").text("冻结");
                }

                //alert(data["MenuList"][0]["MENU_NAME"]);
                var menuList = "";
                for (var i = 0; i < data["MenuList"].length; i++) {
                    if (i%3==0&&i!=0) {
                        menuList += " " + data["MenuList"][i]["MENU_NAME"] + "<br/>";
                    } else {
                        menuList += " " + data["MenuList"][i]["MENU_NAME"] ;
                    }

                }
                $("#RoleInfoModal #div_RoleInfoMenu #lb_RoleMenuInfo").html(menuList);
            }
        });
    }

</script>

<div class="modal fade" id="RoleInfoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">角色详情
                </h4>
            </div>
                <div class="modal-body">

                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">角色名称：</label>
                        <div class="col-md-9">
                            <label id="lb_RoleName" class="col-md-3 control-label" for="text-input"></label>   

                        </div>
                    </div>
                    <hr />
                    
                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">角色描述：</label>
                        <div class="col-md-9">
                            <label id="lb_RoleDescription" style="width:100%" class="col-md-3 control-label" for="text-input"></label>  
                        </div>
                    </div>
                    <hr />

                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">角色状态：</label>
                        <div class="col-md-9">
                            <label id="lb_RoleStatue" class="col-md-3 control-label" for="text-input"></label>  
                        </div>
                    </div>
                    <hr />
                    
                    
                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">角色所具有的菜单权限：</label>
                        <div id="div_RoleInfoMenu" class="col-md-9">
                            <label id="lb_RoleMenuInfo" style="width:100%" class="col-md-3 control-label" for="text-input"></label>  
                        </div>
                    </div>
                    <hr />
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>



